package com.fbt.energy.controller;

import com.fbt.energy.entity.SpEquipment;
import com.fbt.energy.service.SpEquipmentService;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 备件_设备表(SpEquipment)表控制层
 *
 * @author makejava
 * @since 2022-01-21 14:30:41
 */
@RestController
@Api(tags = {"备件_设备表(SpEquipment)表控制层"})
@RequestMapping("/spEquipment")
public class SpEquipmentController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SpEquipmentService spEquipmentService;

    /**
     * 分页查询
     *
     * @param spEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Log(title="备件_设备表")
    @ApiOperation("分页查询列表")
    @GetMapping
    public ResponseEntity<Page<SpEquipment>> queryByPage(SpEquipment spEquipment, PageRequest pageRequest) {
        return ResponseEntity.ok(this.spEquipmentService.queryByPage(spEquipment, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Log(title="备件_设备表")
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("/{id}")
    public ResponseEntity<SpEquipment> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.spEquipmentService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param spEquipment 实体
     * @return 新增结果
     */
    @Log(title="备件_设备表",businessType= BusinessType.INSERT)
    @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<SpEquipment> add(SpEquipment spEquipment) {
        return ResponseEntity.ok(this.spEquipmentService.insert(spEquipment));
    }

    /**
     * 编辑数据
     *
     * @param spEquipment 实体
     * @return 编辑结果
     */
    @Log(title="备件_设备表",businessType=BusinessType.UPDATE)
    @ApiOperation("修改数据")
    @PutMapping
    public ResponseEntity<SpEquipment> edit(SpEquipment spEquipment) {
        return ResponseEntity.ok(this.spEquipmentService.update(spEquipment));
    }

    /**
     * 删除数据
     *
     */
/*    @Log(title="备件_设备表",businessType=BusinessType.DELETE)
    @ApiOperation("根据主键删除数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.spEquipmentService.deleteById(id));
    }*/

}

